home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / sys / amiga / old / amipr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-16  |  6.2 KB  |  273 lines

  1. /* $Id: amipr.c,v 1.1 1993/03/15 21:30:46 mjl Exp $
  2.    $Log: amipr.c,v $
  3.  * Revision 1.1  1993/03/15  21:30:46  mjl
  4.  * Files shuffled around in the Amiga driver reorganization.
  5.  *
  6.  * Revision 1.2  1992/10/12  17:11:19  mjl
  7.  * Amiga-specific mods, including ANSI-fication.
  8.  *
  9.  * Revision 1.1  1992/05/20  21:35:21  furnish
  10.  * Initial checkin of the whole PLPLOT project.
  11.  *
  12. */
  13.  
  14. /*    amipr.c
  15.  
  16.     PLPLOT Amiga (preferences) printer device driver.
  17.     Most of the code is in plsupport.c where it is shared with the
  18.     menu selection printer dump.
  19. */
  20.  
  21. #include "plplot.h"
  22. #include <stdio.h>
  23. #include "dispatch.h"
  24. #include "plamiga.h"
  25.  
  26. /* top level declarations */
  27.  
  28. static long bmapx, bmapy, bmapxmax, bmapymax, xdpi, ydpi;
  29. static long dwidth, dheight;
  30.  
  31. /* (dev) will get passed in eventually, so this looks weird right now */
  32.  
  33. static PLDev device;
  34. static PLDev (*dev) = &device;
  35.  
  36. /*----------------------------------------------------------------------*\
  37. * amipr_init()
  38. *
  39. * Initialize device.
  40. \*----------------------------------------------------------------------*/
  41.  
  42. void
  43. amipr_init(PLStream *pls)
  44. {
  45.     int mode;
  46.  
  47.     pls->termin = 0;        /* not an interactive terminal */
  48.     pls->icol = 1;
  49.     pls->width = 1;
  50.     pls->bytecnt = 0;
  51.     pls->page = 0;
  52.  
  53.     if (openprinter())
  54.     plexit("");
  55.  
  56.     mode = queryprint(&bmapx, &bmapy, &bmapxmax, &bmapymax, &xdpi, &ydpi);
  57.  
  58. /* If mode == 1 we want to adjust the bitmap size so that the aspect
  59.    ratio is maintained. 
  60. */
  61.     if (mode) {
  62.     if ((float) bmapxmax * bmapy > (float) bmapymax * bmapx)
  63.         bmapy = (int) (((float) bmapx * bmapymax) / bmapxmax + .5);
  64.     else
  65.         bmapx = (int) (((float) bmapy * bmapxmax) / bmapymax + .5);
  66.     }
  67.  
  68. /* Leave a little space for pen width. */
  69.  
  70.     dwidth = bmapx - 2;
  71.     dheight = bmapy - 2;
  72.  
  73. /* Set up device parameters */
  74.  
  75.     dev->xold = UNDEFINED;
  76.     dev->yold = UNDEFINED;
  77.     dev->xmin = 0;
  78.     dev->xmax = bmapxmax;
  79.     dev->ymin = 0;
  80.     dev->ymax = bmapymax;
  81.  
  82.     if (!pls->orient) {
  83.     setpxl((PLFLT) (ydpi / 25.4), (PLFLT) (xdpi / 25.4));
  84.     setphy(0, bmapymax, 0, bmapxmax);
  85.     }
  86.     else {
  87.     setpxl((PLFLT) (xdpi / 25.4), (PLFLT) (ydpi / 25.4));
  88.     setphy(0, bmapxmax, 0, bmapymax);
  89.     }
  90.  
  91. /* Allocate bitmap and initial for line drawing */
  92.  
  93.     if (mapinit(bmapx, bmapy)) {
  94.     closeprinter();
  95.     plexit("");
  96.     }
  97. }
  98.  
  99. /*----------------------------------------------------------------------*\
  100. * amipr_line()
  101. *
  102. * Draw a line in the current color from (x1,y1) to (x2,y2).
  103. \*----------------------------------------------------------------------*/
  104.  
  105. void 
  106. amipr_line(PLStream *pls, PLSHORT x1a, PLSHORT y1a, PLSHORT x2a, PLSHORT y2a)
  107. {
  108.     int x1=x1a, y1=y1a, x2=x2a, y2=y2a;
  109.     long xn1, yn1, xn2, yn2;
  110.  
  111.     if (!pls->orient) {
  112.     xn1 = (x1 * dheight) / bmapymax;
  113.     yn1 = (y1 * dwidth) / bmapxmax;
  114.     xn2 = (x2 * dheight) / bmapymax;
  115.     yn2 = (y2 * dwidth) / bmapxmax;
  116.     switch (pls->width) {
  117.     case 3:
  118.         mapline(yn1, xn1, yn2, xn2);
  119.     case 2:
  120.         mapline(yn1 + 2, xn1 + 2, yn2 + 2, xn2 + 2);
  121.     case 1:
  122.     default:
  123.         mapline(yn1 + 1, xn1 + 1, yn2 + 1, xn2 + 1);
  124.     }
  125.     }
  126.     else {
  127.     xn1 = (x1 * dwidth) / bmapxmax;
  128.     yn1 = (y1 * dheight) / bmapymax;
  129.     xn2 = (x2 * dwidth) / bmapxmax;
  130.     yn2 = (y2 * dheight) / bmapymax;
  131.     switch (pls->width) {
  132.     case 3:
  133.         mapline(xn1, dheight - yn1, xn2, dheight - yn2);
  134.     case 2:
  135.         mapline(xn1 + 2, dheight - yn1 + 2, xn2 + 2, dheight - yn2 + 2);
  136.     case 1:
  137.     default:
  138.         mapline(xn1 + 1, dheight - yn1 + 1, xn2 + 1, dheight - yn2 + 1);
  139.     }
  140.     }
  141. }
  142.  
  143. /*----------------------------------------------------------------------*\
  144. * amipr_polyline()
  145. *
  146. * Draw a polyline in the current color.
  147. \*----------------------------------------------------------------------*/
  148.  
  149. void 
  150. amipr_polyline (PLStream *pls, PLSHORT *xa, PLSHORT *ya, PLINT npts)
  151. {
  152.     PLINT i;
  153.  
  154.     for (i=0; i<npts-1; i++) 
  155.       amipr_line( pls, xa[i], ya[i], xa[i+1], ya[i+1] );
  156. }
  157.  
  158. /*----------------------------------------------------------------------*\
  159. * amipr_clear()
  160. *
  161. * Clear page. 
  162. \*----------------------------------------------------------------------*/
  163.  
  164. void 
  165. amipr_clear(PLStream *pls)
  166. {
  167.     dmpport(0L, bmapx, bmapy);
  168.     /* Eject the page. */
  169.     ejectpage();
  170. }
  171.  
  172. /*----------------------------------------------------------------------*\
  173. * amipr_page()
  174. *
  175. * Set up for the next page.  
  176. * Advance to next family file if necessary (file output).
  177. \*----------------------------------------------------------------------*/
  178.  
  179. void 
  180. amipr_page(PLStream *pls)
  181. {
  182.     mapclear();
  183.     pls->page++;
  184. }
  185.  
  186. /*----------------------------------------------------------------------*\
  187. * amipr_adv()
  188. *
  189. * Advance to the next page.
  190. \*----------------------------------------------------------------------*/
  191.  
  192. void 
  193. amipr_adv(PLStream *pls)
  194. {
  195.     amipr_clear(pls);
  196.     amipr_page(pls);
  197. }
  198.  
  199. /*----------------------------------------------------------------------*\
  200. * amipr_tidy()
  201. *
  202. * Close graphics file or otherwise clean up.
  203. \*----------------------------------------------------------------------*/
  204.  
  205. void 
  206. amipr_tidy(PLStream *pls)
  207. {
  208.     dmpport(0L, bmapx, bmapy);
  209.     mapfree();
  210.     closeprinter();
  211.     pls->page = 0;
  212.     pls->OutFile = NULL;
  213. }
  214.  
  215. /*----------------------------------------------------------------------*\
  216. * amipr_color()
  217. *
  218. * Set pen color.
  219. \*----------------------------------------------------------------------*/
  220.  
  221. void 
  222. amipr_color(PLStream *pls)
  223. {
  224. }
  225.  
  226. /*----------------------------------------------------------------------*\
  227. * amipr_text()
  228. *
  229. * Switch to text mode.
  230. \*----------------------------------------------------------------------*/
  231.  
  232. void 
  233. amipr_text(PLStream *pls)
  234. {
  235. }
  236.  
  237. /*----------------------------------------------------------------------*\
  238. * amipr_graph()
  239. *
  240. * Switch to graphics mode.
  241. \*----------------------------------------------------------------------*/
  242.  
  243. void 
  244. amipr_graph(PLStream *pls)
  245. {
  246. }
  247.  
  248. /*----------------------------------------------------------------------*\
  249. * amipr_width()
  250. *
  251. * Set pen width.
  252. \*----------------------------------------------------------------------*/
  253.  
  254. void 
  255. amipr_width(PLStream *pls)
  256. {
  257.     if (pls->width < 1)
  258.     pls->width = 1;
  259.     else if (pls->width > 3)
  260.     pls->width = 3;
  261. }
  262.  
  263. /*----------------------------------------------------------------------*\
  264. * amipr_esc()
  265. *
  266. * Escape function.
  267. \*----------------------------------------------------------------------*/
  268.  
  269. void 
  270. amipr_esc(PLStream *pls, PLINT op, char *ptr)
  271. {
  272. }
  273.